package com.zhengsanming.web;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zhengsanming.pojo.Brand;
import com.zhengsanming.service.BrandService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;

@WebServlet("/add")
public class AddServlet extends HttpServlet {
    BrandService brandService = new BrandService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        String brandName = req.getParameter("brandName");
        //获取请求体
        BufferedReader reader = req.getReader();
        String s = reader.readLine();
        Brand Brand = JSON.parseObject(s, Brand.class);
        brandService.add(Brand);
        resp.setContentType("text/json;charset=utf-8");
        resp.getWriter().write("success");
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
